home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / daemons / ipServer / RCS / tcpTrace.c,v < prev    next >
Encoding:
Text File  |  1989-03-23  |  7.5 KB  |  360 lines

  1. head     1.3;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.3
  10. date     89.03.23.09.57.03;  author brent;  state Exp;
  11. branches ;
  12. next     1.2;
  13.  
  14. 1.2
  15. date     88.08.16.11.20.32;  author mendel;  state Exp;
  16. branches ;
  17. next     1.1;
  18.  
  19. 1.1
  20. date     88.04.27.08.52.43;  author brent;  state Exp;
  21. branches ;
  22. next     ;
  23.  
  24.  
  25. desc
  26. @TCP Trace module
  27. @
  28.  
  29.  
  30. 1.3
  31. log
  32. @Removed stdio.h include
  33. @
  34. text
  35. @/*
  36.  * tcpTrace.c --
  37.  *
  38.  *    Routines to log traces of major events that occur for a TCP socket.
  39.  *
  40.  *    Based on 4.3BSD    @@(#)tcp_debug.c    7.1 (Berkeley) 6/5/86
  41.  *
  42.  * Copyright 1987 Regents of the University of California
  43.  * All rights reserved.
  44.  * Permission to use, copy, modify, and distribute this
  45.  * software and its documentation for any purpose and without
  46.  * fee is hereby granted, provided that the above copyright
  47.  * notice appear in all copies.  The University of California
  48.  * makes no representations about the suitability of this
  49.  * software for any purpose.  It is provided "as is" without
  50.  * express or implied warranty.
  51.  */
  52.  
  53. #ifndef lint
  54. static char rcsid[] = "$Header: /sprite/src/daemons/ipServer/RCS/tcpTrace.c,v 1.2 88/08/16 11:20:32 mendel Exp Locker: brent $ SPRITE (Berkeley)";
  55. #endif not lint
  56.  
  57.  
  58. #include "sprite.h"
  59. #include "netInet.h"
  60. #include "ipServer.h"
  61. #include "tcp.h"
  62. #include "tcpInt.h"
  63. #include "tcpTimer.h"
  64.  
  65. /*
  66.  * A TraceRecord contains a snapshot of important information.
  67.  */
  68. typedef  struct    {
  69.     int            time;        /* Time when the trace routine was 
  70.                      * called. */
  71.     TCPTraceCmd        command;    /* The type of tracing desired. */
  72.     int            prevState;    /* Previous state of the TCP control 
  73.                      * block. */
  74.     Net_TCPHeader    header;        /* TCP header to be logged. */
  75.     TCPControlBlock    controlBlock;    /* Contents of the control block. */
  76. } TraceRecord;
  77.  
  78. static char    *traceNames[] = {
  79.     "Input", "Output", "Respond", "Drop"
  80. };
  81.  
  82. static char *flagNames[] = { "FIN", "SYN", "RESET", "PUSH", "ACK", "URG",};
  83.  
  84. char *tcbStateNames[] = {
  85.     "CLOSED",
  86.     "LISTEN",
  87.     "SYN_SENT",
  88.     "SYN_RECEIVED",
  89.     "ESTABLISHED",
  90.     "CLOSE_WAIT",
  91.     "LAST_ACK",
  92.     "FIN_WAIT_1",
  93.     "FIN_WAIT_2",
  94.     "CLOSING",
  95.     "TIME_WAIT",
  96. };
  97.  
  98. #define NUM_TRACES 100
  99. static TraceRecord traceArray[NUM_TRACES];
  100. static int traceNum = 0;
  101.  
  102.  
  103.  
  104. /*
  105.  *----------------------------------------------------------------------
  106.  *
  107.  * TCPTrace --
  108.  *
  109.  *    Used to trace important changes to a TCP control block.
  110.  *
  111.  * Results:
  112.  *    None.
  113.  *
  114.  * Side effects:
  115.  *    The traceArray is updated.
  116.  *
  117.  *----------------------------------------------------------------------
  118.  */
  119.  
  120. void
  121. TCPTrace(command, prevState, tcbPtr, headerPtr, dataLen)
  122.     TCPTraceCmd        command;    /* Type of trace. */
  123.     int            prevState;    /* Previous TCB state. */
  124.     TCPControlBlock    *tcbPtr;    /* TCB to be saved. */
  125.     Net_TCPHeader    *headerPtr;    /* TCP header to be saved. */
  126.     int            dataLen;    /* Amount of data in the packet. */
  127. {
  128.     register TraceRecord *tracePtr;
  129.     TCPSeqNum    seq;
  130.     TCPSeqNum    ack;
  131.  
  132.     tracePtr = &traceArray[traceNum];
  133.     traceNum += 1;
  134.     if (traceNum == NUM_TRACES) {
  135.     traceNum = 0;
  136.     }
  137.  
  138.     tracePtr->time    = IPS_GetTimestamp();
  139.     tracePtr->command    = command;
  140.     tracePtr->prevState    = prevState;
  141.  
  142.     if (tcbPtr != NULL) {
  143.     tracePtr->controlBlock = *tcbPtr;
  144.     } else {
  145.     bzero((Address)&tracePtr->controlBlock, sizeof(*tcbPtr));
  146.     }
  147.     if (headerPtr != NULL) {
  148.     tracePtr->header = *headerPtr;
  149.     } else {
  150.     bzero((Address)&tracePtr->header, sizeof(*headerPtr));
  151.     }
  152.  
  153.     if (!ips_Debug) {
  154.     return;
  155.     }
  156.  
  157.     (void) printf("%s: ", traceNames[(int)command]);
  158.  
  159.     if (tcbPtr != NULL) {
  160.     (void) printf("%x %s:", tcbPtr, tcbStateNames[(int)prevState]);
  161.     } else {
  162.     (void) printf("???????? ");
  163.     }
  164.  
  165.     switch (command) {
  166.  
  167.     case TCP_TRACE_INPUT:
  168.     case TCP_TRACE_OUTPUT:
  169.     case TCP_TRACE_DROP:
  170.         if (headerPtr == NULL) {
  171.         break;
  172.         }
  173.         seq = headerPtr->seqNum;
  174.         ack = headerPtr->ackNum;
  175.         if (command == TCP_TRACE_OUTPUT) {
  176.         seq = Net_NetToHostInt(seq);
  177.         ack = Net_NetToHostInt(ack);
  178.         }
  179.         if (dataLen != 0) {
  180.         (void) printf("[%x..%x)", seq, seq+dataLen);
  181.         } else {
  182.         (void) printf("%x", seq);
  183.         }
  184.         (void) printf("@@%x, urgent=%x", ack, headerPtr->urgentOffset);
  185.         if (headerPtr->flags!= 0) {
  186.         TCPPrintHdrFlags(stdout, headerPtr->flags);
  187.         }
  188.         break;
  189.     }
  190.  
  191.     /* 
  192.      * Print out internal state of *tcbPtr.
  193.      */
  194.  
  195.     if (tcbPtr != NULL) {
  196.     (void) printf(" -> %s\n", tcbStateNames[(int)tcbPtr->state]);
  197.  
  198.     (void) printf("\trecv.(next,window,urgPtr) (%x,%x,%x)\n",
  199.         tcbPtr->recv.next, tcbPtr->recv.window, tcbPtr->recv.urgentPtr);
  200.     (void) printf("\tsend.(unAck,next,maxSent) (%x,%x,%x)\n",
  201.         tcbPtr->send.unAck, tcbPtr->send.next, tcbPtr->send.maxSent);
  202.     (void) printf("\tsend.(updateSeq#,updateAck#,window) (%x,%x,%x)\n",
  203.         tcbPtr->send.updateSeqNum, tcbPtr->send.updateAckNum, 
  204.         tcbPtr->send.window);
  205.     }
  206.     (void) printf("\n");
  207. }
  208.  
  209.  
  210. /*
  211.  *----------------------------------------------------------------------
  212.  *
  213.  * TCPPrintHdrFlags --
  214.  *
  215.  *    Prints the state of the flags in the TCP header.
  216.  *
  217.  * Results:
  218.  *    None.
  219.  *
  220.  * Side effects:
  221.  *    None.
  222.  *
  223.  *----------------------------------------------------------------------
  224.  */
  225.  
  226. void
  227. TCPPrintHdrFlags(stream, flags)
  228.     FILE        *stream;    /* Where to print. */
  229.     unsigned short    flags;        /* TCP packet header flags. */
  230. {
  231.     register int i;
  232.  
  233.     char *cp = "<";
  234.     for (i=0; i < 6; i++) {
  235.     if ((1 << i) & flags) {
  236.         (void) fprintf(stream, "%s%s", cp, flagNames[i]);
  237.         cp = ", ";
  238.     }
  239.     }
  240.     (void) fprintf(stream, ">");
  241. }
  242.  
  243.  
  244. /*
  245.  *----------------------------------------------------------------------
  246.  *
  247.  * TCP_PrintInfo --
  248.  *
  249.  *    A routine to print out the state of a TCB.
  250.  *
  251.  * Results:
  252.  *    None.
  253.  *
  254.  * Side effects:
  255.  *    None.
  256.  *
  257.  *----------------------------------------------------------------------
  258.  */
  259.  
  260. void
  261. TCP_PrintInfo(data)
  262.     ClientData    data;        /* Really a pointer to a TCP. */
  263. {
  264.     TCPControlBlock *tcbPtr = (TCPControlBlock *) data;
  265.  
  266.     if (tcbPtr != (TCPControlBlock *) NULL) {
  267.     (void) fprintf(stderr, 
  268.         "%10s flags=%x unAck=%d s.next=%d r.next=%d\n",
  269.         tcbStateNames[(int)tcbPtr->state],
  270.         tcbPtr->flags,
  271.         tcbPtr->send.unAck,
  272.         tcbPtr->send.next,
  273.         tcbPtr->recv.next);
  274.     }
  275. }
  276. @
  277.  
  278.  
  279. 1.2
  280. log
  281. @Converted to use new libc.a
  282. @
  283. text
  284. @d20 1
  285. a20 1
  286. static char rcsid[] = "$Header: tcpTrace.c,v 1.1 88/04/27 08:52:43 brent Exp $ SPRITE (Berkeley)";
  287. a29 2
  288.  
  289. #include <stdio.h>
  290. @
  291.  
  292.  
  293. 1.1
  294. log
  295. @Initial revision
  296. @
  297. text
  298. @d20 1
  299. a20 1
  300. static char rcsid[] = "$Header: tcpTrace.c,v 6.0 87/09/08 15:57:30 andrew Stable $ SPRITE (Berkeley)";
  301. d31 1
  302. a31 2
  303. #include "byte.h"
  304. #include "io.h"
  305. d113 1
  306. a113 1
  307.     Byte_Zero(sizeof(*tcbPtr), (Address)&tracePtr->controlBlock);
  308. d118 1
  309. a118 1
  310.     Byte_Zero(sizeof(*headerPtr), (Address)&tracePtr->header);
  311. d125 1
  312. a125 1
  313.     Io_Print("%s: ", traceNames[(int)command]);
  314. d128 1
  315. a128 1
  316.     Io_Print("%x %s:", tcbPtr, tcbStateNames[(int)prevState]);
  317. d130 1
  318. a130 1
  319.     Io_Print("???????? ");
  320. d148 1
  321. a148 1
  322.         Io_Print("[%x..%x)", seq, seq+dataLen);
  323. d150 1
  324. a150 1
  325.         Io_Print("%x", seq);
  326. d152 1
  327. a152 1
  328.         Io_Print("@@%x, urgent=%x", ack, headerPtr->urgentOffset);
  329. d154 1
  330. a154 1
  331.         TCPPrintHdrFlags(io_StdOut, headerPtr->flags);
  332. d164 1
  333. a164 1
  334.     Io_Print(" -> %s\n", tcbStateNames[(int)tcbPtr->state]);
  335. d166 1
  336. a166 1
  337.     Io_Print("\trecv.(next,window,urgPtr) (%x,%x,%x)\n",
  338. d168 1
  339. a168 1
  340.     Io_Print("\tsend.(unAck,next,maxSent) (%x,%x,%x)\n",
  341. d170 1
  342. a170 1
  343.     Io_Print("\tsend.(updateSeq#,updateAck#,window) (%x,%x,%x)\n",
  344. d174 1
  345. a174 1
  346.     Io_Print("\n");
  347. d196 1
  348. a196 1
  349.     Io_Stream        stream;        /* Where to print. */
  350. d204 1
  351. a204 1
  352.         Io_PrintStream(stream, "%s%s", cp, flagNames[i]);
  353. d208 1
  354. a208 1
  355.     Io_PrintStream(stream, ">");
  356. d235 1
  357. a235 1
  358.     Io_PrintStream(io_StdErr, 
  359. @
  360.